import './assets/global.css'
import axios from 'axios'
import ElementPlus from 'element-plus'
// 如果您正在使用CDN引入，请删除下面一行。
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import 'element-plus/dist/index.css'
import {createApp, ref} from 'vue'
// @ts-ignore
import App from './App.vue'
import router from './router'

const app = createApp(App)

//定义 user 接口
interface user {
    id: number;
    username: string;
    password: string;
    phone: string;
    email: string;
    avatar: string
    role: string;
    status: number;
    created_at: string;
    updated_at: string;
}

//创建全局的用户状态
const userState = ref<user>([]);

axios.defaults.baseURL = '/api';
axios.defaults.headers.post["Content-Type"] = "application/json;charset=utf-8";

/*
将 axios挂载为Vue的一个自定义属性$http
在组件文件中这样使用:
import { getCurrentInstance } from 'vue'
const global = getCurrentInstance().appContext.config.globalProperties;
global.$http.get()|post()|put()|delete()
*/
app.config.globalProperties.$http = axios;

//提供全局状态
app.provide('userState',userState)

app.use(ElementPlus, {size: 'default', locale: zhCn})
app.use(router)
//注册字体图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

app.mount('#app')
